<%@page import="service.UserService"%>
<%@page import="entities.UserEntity"%>
<%@page import="service.TCartService"%>
<%@page import="entities.CartEntity"%>
<%@page import="util.Util"%>
<%@ page language="java" import="java.util.*,alipay.*"
	pageEncoding="utf-8"%>
<%
	//设置页面不缓存
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
	//支付宝
	Date Now_Date = new Date();
	String paygateway = "https://www.alipay.com/cooperate/gateway.do?"; //'支付接口
	String service = "create_direct_pay_by_user";//快速付款交易服务
	String sign_type = "MD5";
	String out_trade_no = Now_Date.toString(); //商户网站订单
	String input_charset = "utf-8";
	String partner = ""; //支付宝合作伙伴id (账户内提取)
	String key = ""; //支付宝安全校验码(账户内提取)
	String body = "阿"; //商品阿描述，推荐格式：商品名称（订单编号：订单编号）
	String total_fee = "0.01"; //订单总价
	String payment_type = "1";//支付宝类型.1代表商品购买
	String seller_email = ""; //卖家支付宝帐户
	String subject = "AAA:" + out_trade_no; //商品名称
	String show_url = "www.sina.com.cn";
	String notify_url = Util.BASE_URL + "alipay/alipay_notify.jsp"; //通知接收URL
	String return_url = Util.BASE_URL + "alipay/alipay_return.jsp"; //支付完成后跳转返回的网址URL

	String ItemUrl = Payment.CreateUrl(paygateway, service, sign_type,
			out_trade_no, input_charset, partner, key, show_url, body,
			total_fee, payment_type, seller_email, subject, notify_url,
			return_url);

	String userName = (String) session.getAttribute("userName");
	UserEntity user = null;
	List<CartEntity> cartList = new ArrayList<CartEntity>();
	if (userName == null) {
		response.sendRedirect("logReg.jsp?action=login");
	} else {
		//获得用户信息
		user = UserService.getUser(userName);
		//获得购物车数据
		cartList = TCartService.selectAll(userName);
	}
%>

<!DOCTYPE HTML>
<html>
<head>

<title>订单确认-<%=userName%></title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" type="text/css" href="css/cart.css">
<link rel="stylesheet" type="text/css" href="css/cartConfirm.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/tCartConfirm.js"></script>

</head>

<body>
	<jsp:include page="header.jsp"></jsp:include>
	<div style="height: 30px;" id="userName"><%=userName%></div>
	<div class="cartConfirm">
		<div class="head">
			<span
				style="float: left;font-size:22px;margin-top:20px;color: green;">订单信息确认</span>
			<div class="step" style="float:right;margin:20px 0 0;">
				<img src="images/cart_step2_v1.jpg">
			</div>
		</div>
		<div class="info">
			配送信息 <span style="color: red;font-size: 13px;">请认真核对以下信息:</span> <a
				href="javascript:;">修改默认送货信息</a>
		</div>
		<div class="deliverInfo">
			<ul>
				<li><a>收餐人姓名(必填)</a><a id="UserNameTip" class="InputErrorTips"></a>
				</li>
				<li><input type="text" class="textBox" id="UserNameTextBox"
					value="<%=user.getName()%>" />
				</li>
				<li><a>手机号码(必填)</a><a id="PhoneNumTip" class="InputErrorTips"></a>
				</li>
				<li><input type="text" class="textBox" id="PhoneNumTextBox"
					value="<%=user.getTel()%>" />
				</li>
				<li><a>送餐地址(必填)</a><a id="AddressTip" class="InputErrorTips"></a>
				</li>
				<li><input type="text" class="textBox" id="AddressTextBox"
					value="<%=user.getAddr()%>" />
				</li>
				<li><a>其他送餐要求</a><a id="MoreTip" class="InputErrorTips"></a></li>
				<li><input type="text" class="textBox" value="希望商家尽早送餐"
					id="MoreTextBox"></li>
			</ul>

		</div>

		<div class="payInfo">
			<ul>
				<li class="payWay">支付方式 &gt;&gt;</li>
				<li>1. 支付宝付款 :</li>
				<li><input type="radio" class="alipay" value="alipay" checked="checked"/><img
					src="images/alipay.PNG" />
				</li>
				<li>&nbsp;</li>
				<li>&nbsp;<br/><br/>
				</li>
			</ul>
		</div>
		<div class="info">
			订单详情 [<a class="hide" href="javascript:void(0);return false;"
				style="float: none;font-size: 13px;">隐藏/显示</a>]
		</div>
		<div class="cart">
			<%
				if (cartList.size() != 0) {
			%>
			<div class="cart_products">
				<table width="100%">
						<tbody>
							<tr>
								<th width="170">产品</th>
								<th></th>
								<th width="120">数量</th>
								<th width="120">价格</th>
								<th width="180">总价</th>
								<th width="65">操作</th>
							</tr>
							<%
								double totalPrice = 0d;
								for (CartEntity cart : cartList) {
								totalPrice += cart.getGoodsPrice() * cart.getItemCount();
							%>
							<tr class="cart_item" id="<%=cart.getGoodsId()%>">
									<td class="product_box" width="120"><div class="pic">
											<a href="goodsDetail.jsp?goodsId=<%=cart.getGoodsId()%>"
												target="_blank"> <img width="110" height="70"
												src="<%=cart.getGoodsImg()%>"> </a>
										</div>
									</td>
								<td class="name">
									<div style="width:259px;position: relative;">
										<a href="goodsDetail.jsp?goodsId=<%=cart.getGoodsId()%>"
											target="_blank"> <%=cart.getGoodsName()%> </a> <a
											class="sellerName"
											href="menu.jsp?sellerId=<%=cart.getSellerId()%>"
											target="_blank">【<%=cart.getSellerName()%>】</a>
										<div class="itemTime"><%=cart.getItemTime()%></div>
									</div></td>
								<td class="number_box text_left"><div
										class="buy_number_input">
										<span id="goodsId" style="display: none;"><%=cart.getGoodsId() %></span>
										<span class="decrease_num"></span> <input
											class="item-buy-quantity-input"
											value="<%=cart.getItemCount()%>" /> <span class="increase_num"></span>
									</div>
								</td>
								<td class="price_box">¥<span><%=cart.getGoodsPrice()%></span>
								</td>
								<td class="count_price_box">¥<span><%=cart.getGoodsPrice() * cart.getItemCount()%></span>
								</td>
								<td class="action_box"><a class="item-buy-delete"
									href="javascript:void(0)">取消</a></td>
							</tr>
							<%
								}
							%>
							<tr class="no_border">
								<td colspan="6" class="count">
									应付总额 ：<span class="totalPrice"> ¥<span><%=totalPrice%></span>
								</span></td>
							</tr>
						</tbody>
					</table>
			</div>
			<%
				}
			%>
		</div>

		<div align="center" class="confirm">
			<a class="btn_pink_big" id="sure" rel="<%=ItemUrl%>"
				href="javascript:void(0);">确定团购</a>
		</div>
	</div>
	<jsp:include page="footer.jsp"></jsp:include>
</body>
</html>
